package zzjson.rabbitmq.transaction;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import zzjson.rabbitmq.BaseRabbitMq;

import java.io.IOException;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : zzjson.rabbitmq.transaction</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年04月29日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class Transaction {
	public static String QUEUENAME = "TRANSACTION_QUEUE";

	public static void main(String[] args) throws IOException {
		Connection conn = BaseRabbitMq.getConn();
		Channel channel = conn.createChannel();
		channel.queueDeclare(QUEUENAME, false, false, false, null);
		try {
			channel.txSelect();

			//发送消息
			channel.basicPublish("", QUEUENAME, null, "测试字符串".getBytes());

			//int i = 1/0;

			channel.txCommit();
			System.out.println("消息发送成功");
		} catch (Exception e) {
			channel.txRollback();
			System.out.println("消息发送失败");
			e.printStackTrace();
		}

		BaseRabbitMq.close(channel, conn);

	}
}